<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class Driver extends Base
{
    protected $insert = ['addtime'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }
    public function getAddtimeTextAttr($value,$data){
        return date("Y-m-d H:i:s",$data['addtime']);
    }

    public function getImageTextAttr($value,$data){
        return $data['image'] ? cdnurl($data['image'],true) : "";
    }
 
     /**
     * 登录
     */
    public function login($params)
    {
        $data = $this->where('account', $params['account'])->find();
        if (empty($data)) {
            return self::errorResult('账号不存在');
        }
        if ($data['password'] != StrMD5($params['password'])) {
            return self::errorResult('密码错误');
        }
        // if ($data['state'] == 1) {
        //     return self::errorResult('此账号被禁用');
        // }
        session('Agent', $data);
  
        return self::successResult($data);
    }

    public function num($id){
        $user = (new \app\common\model\AgentEwm())->where(['id' => $id])->find();
    }
    public function getSBusTextAttr($value,$data){
        if(empty($data['s_bus_id'])){
            return '';
        }
        return implode(",",(new \app\common\model\Bus())->where('id','in',$data['s_bus_id'])->column('nickname'));
    }
    public function getQBusTextAttr($value,$data){
        if(empty($data['s_bus_id'])){
            return '';
        }
        return implode(",",(new \app\common\model\Bus())->where('id','in',$data['q_bus_id'])->column('nickname'));
    }
}
